<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class MUserFilter extends MApplicationComponent
implements MIController
{

    
    public function invoke($uri=null)
    {
        $path = explode('?', $uri);
        $parts = array_slice(explode('/', $path[0]), 1);
        if (isset($parts[0]) && $parts[0] == "oauth") {
            return;
        }

        if (OAuthRequestVerifier::requestIsSigned())
        {
            try
            {
                $req = new OAuthRequestVerifier();
                $device_id = $req->verify();
            }
            catch (OAuthException2 $e)
            {
                                                                                                                                                                                header('HTTP/1.1 401 Unauthorized');
                header('WWW-Authenticate: OAuth realm=""');
                header('Content-Type: text/plain; charset=utf8');

                echo $e->getMessage();
                exit();
                            }
                        if ($device_id)
            {
                $user = MUserManager::getInstance()->getUser($device_id);                if($user->user_status  == 0){
                	throw new MAuthorizationException("User has disabled.", MConst::HTTP_CODE_407);
                }
                $user->appId = $req->getOsrId();            }
        } else {
            throw new MFileopsException(FXP::t("Bad OAuth request."), MConst::HTTP_CODE_403);
        }
    }
}
?>